home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / lanutsrc.zip / LUSETUP.C < prev    next >
Text File  |  1991-10-23  |  10KB  |  337 lines

  1. /* LUSETUP.C allows you to set colors and hotkeys for INTERCOM and
  2.    some versions of Artisoft's LANPUP utility.  Although I'm including
  3.    source for LUSETUP, it requires a proprietary video library which
  4.    I cannot distribute.  This source code contains the proper techniques
  5.    and addresses for changing colors and hotkeys, so you should be able
  6.    to adapt it for whatever video library you prefer. */
  7.  
  8.  
  9. /* now being used to set colors and hotkeys */
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <dos.h>
  14.  
  15. #include <\c\io\screenio.h>
  16. #include <\c\io\iowin.h>
  17. #include <\c\io\keyboard.h>
  18.  
  19. /* aaargh! Define all the scan codes for the standard kbd_table */          
  20. char *kbd_table[] = {"","1","2","3","4","5","6","7","8","9","0","-","=","",          
  21.                     "","q","w","e","r","t","y","u","i","o","p","[","]","",
  22.                    "","a","s","d","f","g","h","j","k","l",";","'",
  23.                    "","","\\","z","x","c","v","b","n","m",",",".","/","",
  24.                    ""," ","" };
  25.                    
  26. #define NUM_KEYCODES 59
  27.  
  28. FIELD screen[] = {
  29.   {2,3,32,MENU_ITEM,0,NULL,3,1,3,1,NULL,NULL,NULL,NULL},
  30.   {3,3,32,MENU_ITEM,0,NULL,0,2,0,2,NULL,NULL,NULL,NULL},
  31.   {4,3,32,MENU_ITEM,0,NULL,1,3,1,3,NULL,NULL,NULL,NULL},
  32.   {5,3,32,MENU_ITEM,0,NULL,2,0,2,0,NULL,NULL,NULL,NULL}  
  33. };
  34.  
  35. int toggles[4] = {0,0,0,0};
  36. int members[4] = {0,1,2,3};
  37. char hotkey[10];
  38.  
  39. FIELD kscreen[] = {
  40.   {7, 10,15,TOGGLE_FIELD,1,&members[0],3,1,4,4,NULL,NULL,NULL,(char *) &toggles[0]},
  41.   {8, 10,15,TOGGLE_FIELD,1,&members[1],0,2,4,4,NULL,NULL,NULL,(char *) &toggles[1]},
  42.   {9, 10,15,TOGGLE_FIELD,1,&members[2],1,3,4,4,NULL,NULL,NULL,(char *) &toggles[2]},
  43.   {10,10,15,TOGGLE_FIELD,1,&members[3],2,3,4,4,NULL,NULL,NULL,(char *) &toggles[3]},
  44.   {7,40,1, TEXT_FIELD,  0,NULL,3,0,0,0,NULL,NULL,NULL,hotkey}  
  45. };
  46.  
  47. #define IROW     5
  48. #define ICOL     8
  49. #define ILENGTH  5
  50. #define IWIDTH   63
  51. #define BC       112
  52. #define FC       7
  53.  
  54. #define M_COLOR_LOC  9        /* message's color patch location */
  55.  
  56. #define I_COLOR_LOC 139     /* intercom's color patch location */
  57. #define I_HOTKEY_LOC 140    /* intercom's hotkey patch location */
  58. #define I_SHIFT_STATE 141       /* intercom's shift state info */
  59.  
  60. #define L_HOTKEY_LOC  1196    /* lanpup's hotkey location */
  61. #define L_SHIFT_STATE 1197    /* lanpup's shift state byte */
  62.  
  63. #define ATTRIB (background * 16) + foreground
  64. #define ERRLOC 5,20
  65.  
  66. extern VIDEO_PARMS VIDEO;
  67. extern WINDOW_COLORS COLORS;
  68. extern int field_column;
  69.  
  70. /* find_code ****************************************************************
  71. *****************************************************************************/
  72. int find_code(key)
  73.   char key;
  74. {
  75.   int i;
  76.   
  77.   for (i = 0; i < NUM_KEYCODES;i++) {
  78.     if (key == *kbd_table[i]) return(i + 1);
  79.   }  
  80.   return(FALSE);
  81.   
  82. }
  83.  
  84. /* patch ********************************************************************
  85. *****************************************************************************/
  86. patch(fname,location,newval)
  87.   char *fname;
  88.   long location;
  89.   char newval;
  90. {
  91.   FILE *file;
  92.  
  93.   file = fopen(fname,"r+b");
  94.   if (file != NULL) {
  95.     fseek(file,location,SEEK_SET);
  96.     fwrite((char *) &newval,1,1,file);
  97.     fclose(file);
  98.   }
  99. }
  100.  
  101. /* draw_screen **************************************************************
  102.  
  103. *****************************************************************************/
  104. draw_screen() {
  105.   char clr;
  106.   
  107.   cls();
  108.   
  109.   clr = (VIDEO.color) ? 31:15;
  110.   
  111.   wpaint(0,0,25,80,&clr,1);
  112.   
  113.   write_at(0,0,
  114. "LANutils Setup/Patch Utility Version 2.0  (C) Copyright 1990 by SoftMagic, Inc.",clr);
  115.  
  116.   shadow_box(1,1,7,37,NORMAL,DOUBLE_LINE);
  117.   write_at(1,2,"Main Functions",NORMAL);
  118.  
  119.   write_at(2,3,"Change INTERCOM's screen colors",NORMAL);
  120.   write_at(3,3,"Change MESSAGE's screen colors",NORMAL);
  121.   write_at(4,3,"Change INTERCOM's activation key",NORMAL);
  122.   write_at(5,3,"Change LANPUP's activation key",NORMAL);
  123.  
  124.  
  125.  write_at(24,0,
  126. "Press Enter to select an option, Esc to quit",clr); 
  127.   
  128. }  
  129.  
  130. /* rpatch ********************************************************************
  131.  
  132. *****************************************************************************/
  133. int rpatch(fname,location,newval)
  134.   char *fname;
  135.   long location;
  136.   char *newval;
  137. {
  138.   FILE *file;
  139.  
  140.   file = fopen(fname,"rb");
  141.   if (file != NULL) {
  142.     fseek(file,location,SEEK_SET);
  143.     fread(newval,1,1,file);
  144.     fclose(file);
  145.     return(TRUE);
  146.   }
  147.   else return(FALSE);
  148. }
  149.  
  150. /* set_color ********************************************************
  151.  
  152. *****************************************************************************/
  153. set_color(fname,location)
  154.   char *fname;
  155.   unsigned int location;
  156. {
  157.   unsigned int result,foreground,background,done;
  158.   unsigned char cbyte;
  159.   char string[40];
  160.  
  161.   result = rpatch(fname,(long) location,&cbyte);
  162.   
  163.   if (!result) {
  164.     error(ERRLOC,"Unable to read file.",
  165.                  "Make sure it is in the current directory",
  166.                  "Then try again.",NULL);
  167.     return;
  168.   }               
  169.  
  170.   foreground = cbyte % 16;
  171.   background = cbyte / 16;
  172.   
  173.   save_scr(3,7,17,60);
  174.   shadow_box(3,7,17,60,112,DOUBLE_LINE);
  175.   sprintf(string,"Change screen colors for %s",fname);
  176.   write_at(3,8,string,112);
  177.   
  178.   hline(10,8,57,SINGLE_LINE);
  179.   
  180.   write_at(12,12,"Up & Down arrows    - Change the foreground color",112);
  181.   write_at(13,12,"Left & Right arrows - Change the background color",112);
  182.   write_at(14,12,"Home                - Restore default colors",112);
  183.   write_at(15,12,"Enter               - Save changes and return",112);
  184.   write_at(16,12,"Esc                 - Return without saving changes",112);
  185.  
  186.   done = FALSE;
  187.   while (!done) {
  188.     box(5,17,4,40,ATTRIB,DOUBLE_LINE);
  189.     write_at(6,25,"Sample pop up window text",ATTRIB);
  190.     
  191.     switch (getkey()) {
  192.       case Up:    /* foreground color up */
  193.         foreground = ++foreground % 16;
  194.         break;
  195.       case Dn:    /* foreground color down */
  196.         foreground--;
  197.         if (foreground < 0) foreground = 16;
  198.         break;
  199.       case Left:  /* background color down */
  200.         background--;
  201.         if (background < 0) background = 16;
  202.         break;
  203.       case Right: /* background color up */
  204.         background = ++background % 16;
  205.         break;
  206.       case Home:  /* restore defaults */
  207.         foreground = 0;
  208.         background = 7;
  209.         break;
  210.       case Ret:  /* save and quit */
  211.         done = TRUE;
  212.         patch(fname, (long) location, ATTRIB);
  213.         break;
  214.       case Esc:
  215.         done = TRUE;
  216.         break;
  217.     }  
  218.   }
  219.   restore_scr();
  220. }
  221.  
  222. /* set_hotkey ********************************************************
  223.  
  224. *****************************************************************************/
  225. set_hotkey(fname,keyloc,shiftloc)
  226.   char *fname;
  227.   unsigned int keyloc,shiftloc;
  228. {
  229.   unsigned int result,keycode,shift_status;
  230.   int field,code,old_normal,old_hilite;
  231.   char string[40];
  232.  
  233.   result = rpatch(fname,(long) keyloc,&keycode);
  234.   
  235.   if (!result) {
  236.     error(ERRLOC,"Unable to read file.",
  237.                  "Make sure it is in the current directory",
  238.                  "Then try again.",NULL);
  239.     return;
  240.   }
  241.   
  242.   strcpy(kscreen[4].result,kbd_table[keycode - 1]);
  243.   
  244.   result = rpatch(fname,(long) shiftloc,&shift_status);
  245.   *kscreen[3].result = (shift_status & 1);
  246.   *kscreen[2].result = (shift_status & 2);
  247.   *kscreen[1].result = (shift_status & 4);
  248.   *kscreen[0].result = (shift_status & 8);
  249.   
  250.   old_normal = NORMAL;
  251.   NORMAL = 112;
  252.   old_hilite = HILITE; 
  253.   HILITE = 7;
  254.  
  255.   save_scr(3,7,18,46);
  256.   shadow_box(3,7,18,46,112,DOUBLE_LINE);
  257.   sprintf(string,"Change activation key for %s",fname);
  258.   write_at(3,8,string,112);
  259.   
  260.   write_at(5,10,"Shift Status",BRIGHT);
  261.   box(6,9,6,17,113,SINGLE_LINE);
  262.   write_at(7,13,"Alt",112);
  263.   write_at(8,13,"Ctrl",112);
  264.   write_at(9,13,"Left shift",112);
  265.   write_at(10,13,"Right shift",112);
  266.   
  267.   write_at(5,33,"Activation key",BRIGHT);
  268.   box(6,33,3,15,113,SINGLE_LINE);
  269.   
  270.   hline(13,8,43,SINGLE_LINE);
  271.   
  272.   write_at(15,11,"Space - Select/deselect shift key",112);
  273.   write_at(16,11,"Enter - Save changes and return",112);
  274.   write_at(17,11,"Esc   - Return without saving changes",112);
  275.  
  276.   field = code = 0;
  277.   while (TRUE) {
  278.     do_fields(kscreen,5,&field,&code);
  279.     if (code == Esc) break;
  280.     else if (code == Ret) {
  281.       result = find_code(*kscreen[4].result);
  282.       if (result) patch(fname,(long) keyloc,result);
  283.       else {
  284.         error(ERRLOC,"Sorry, I can't use that key to",
  285.                      "pop up. Pick another one and try",
  286.                      "again.",NULL);
  287.         break;
  288.       }  
  289.       
  290.       result  = (*kscreen[3].result) ? 1:0;
  291.       result |= (*kscreen[2].result) ? 2:0;
  292.       result |= (*kscreen[1].result) ? 4:0;
  293.       result |= (*kscreen[0].result) ? 8:0;
  294.       patch(fname,(long) shiftloc,result);
  295.       break;
  296.     }  
  297.   }  
  298.  
  299.   NORMAL = old_normal;
  300.   HILITE = old_hilite;
  301.   
  302.   restore_scr();
  303. }
  304.  
  305. /* main ********************************************************************
  306.  
  307. *****************************************************************************/
  308. void main() {
  309.   int field,code;
  310.   
  311.   get_video_setup();
  312.  
  313.   draw_screen();
  314.  
  315.   field = code = 0;
  316.   while (TRUE) {
  317.     do_fields(screen,4,&field,&code);
  318.     if (code == Esc) break;
  319.     switch(field) {
  320.       case 0: /* change intercom's colors */
  321.         set_color("INTERCOM.COM",I_COLOR_LOC);
  322.         break;
  323.       case 1: /* change message's color */
  324.         set_color("MESSAGE.COM",M_COLOR_LOC);
  325.         break;
  326.       case 2: /* change intercom's hotkey */
  327.         set_hotkey("INTERCOM.COM",I_HOTKEY_LOC,I_SHIFT_STATE);
  328.         break;
  329.       case 3: /* change lanpup's hotkey */
  330.         set_hotkey("LANPUP.EXE",L_HOTKEY_LOC,L_SHIFT_STATE);
  331.         break;
  332.     }      
  333.   }
  334.   cls();  
  335. }
  336. 
  337.